<template>
  <div>
    <el-card>
      <!-- 头部表单 -->
      <el-form
        :inline="true"
        :model="formInline"
        class="demo-form-inline"
        size="small"
        ref="ruleForm"
        v-show="showSearch"
      >
        <el-form-item label="用户名">
          <el-input
            v-model="formInline.userName"
            placeholder="请输入"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button
            size="mini"
            icon="el-icon-search"
            type="primary"
            @click="onSubmit"
            >查询</el-button
          >
          <el-button
            size="mini"
            icon="el-icon-refresh"
            @click="resize('ruleForm')"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
      <el-row :gutter="10" class="mb8">
        <el-button
          type="primary"
          size="mini"
          @click="
            addVisible = true;
            title = '考核';
          "
          >考核</el-button
        >
        <right-toolbar
          :showSearch.sync="showSearch"
          @queryTable="getList"
        ></right-toolbar>
      </el-row>

      <el-table :data="tableData" height="calc(100vh - 300px)">
        <el-table-column prop="userName" label="用户名" align="center">
        </el-table-column>
        <el-table-column prop="duration" label="表单总耗时" align="center">
        </el-table-column>
        <el-table-column
          prop="completedProcessStatusCount"
          label="完成表单数"
          align="center"
        >
        </el-table-column>
        <el-table-column
          prop="runningProcessStatusCount"
          label="进行表单数"
          align="center"
        >
        </el-table-column>
        <el-table-column prop="processCount" label="表单总数" align="center">
        </el-table-column>
        <el-table-column label="操作" align="center">
          <template slot-scope="scope">
            <el-button
              type="primary"
              size="mini"
              @click="examineAgain(scope.row)"
              >再次考核</el-button
            >
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="formInline.pageNum"
        :limit.sync="formInline.pageSize"
        @pagination="getList"
      />
    </el-card>

    <!-- 添加考核弹窗 -->
    <el-dialog
      :title="title"
      :visible.sync="addVisible"
      width="700px"
      append-to-body
    >
      <el-form ref="addForm" :model="addForm" label-width="110px" size="mini">
        <el-form-item prop="userId" label="选择考核人">
          <el-select
            :disabled="title == '再次考核'"
            @change="changeUserOrTime"
            v-model="addForm.userId"
            placeholder="请选择考核人"
          >
            <el-option
              :label="item.userName"
              :value="item.userId"
              v-for="item in userList"
              :key="item.userId"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="考核时间段">
          <el-date-picker
            value-format="yyyy-MM-dd HH:mm:ss"
            v-model="dateRange"
            type="datetimerange"
            range-separator="至"
            start-placeholder="开始日期"
            end-placeholder="结束日期"
          >
          </el-date-picker>
        </el-form-item>
        <el-form-item label="表单总耗时:">{{
          addForm.duration || 0
        }}</el-form-item>
        <el-form-item label="完成表单数:">{{
          addForm.completedProcessStatusCount || 0
        }}</el-form-item>
        <el-form-item label="进行表单数:">{{
          addForm.runningProcessStatusCount || 0
        }}</el-form-item>
        <el-form-item label="得分">
          <el-input v-model="addForm.score" placeholder="请输入得分"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm('addForm')"
          >添 加</el-button
        >
        <el-button @click="addVisible = false">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listUser } from "@/api/system/user";
import {
  getexamineApi, //获取列表数据
} from "@/api/dataPresentation/alarmCategory.js";
export default {
  data() {
    return {
      //添加考核弹窗隐藏显示
      addVisible: false,
      //弹窗标题
      title: "考核",
      // 总条数
      total: 0,
      // 显示搜索条件
      showSearch: true,
      //列表数据
      tableData: [],
      //查询条件
      formInline: {
        pageNum: 1,
        pageSize: 10,
        userName: undefined,
      },
      //添加考核弹窗
      addForm: {
        userId: null, //考核人id
        beginTime: null, //开始时间
        endTime: null, //结束时间
        duration: null, //考核总耗时
        completedProcessStatusCount: null, //完成表单数
        runningProcessStatusCount: null, //进行表单数
        score: null, //得分
      },
      //用户数据
      userList: [],
      // 日期范围
      dateRange: [],
    };
  },
  methods: {
    //提交表单
    submitForm(formName) {
      console.log(this.dateRange);
      if (this.dateRange && this.dateRange.length) {
        this.addForm.beginTime = this.dateRange[0];
        this.addForm.endTime = this.dateRange[1];
      }
      console.log(this.addForm);
    },
    //切换考核用户或时间段
    changeUserOrTime(userId) {},
    //获取用户数据
    listUser() {
      listUser({ pageNum: 1, pageSize: 1000 }).then((res) => {
        this.userList = res.rows;
      });
    },
    //获取数据
    getList() {
      getexamineApi(this.formInline).then((res) => {
        if (res) {
          this.tableData = res.rows;
          this.total = res.total;
        }
      });
    },
    //查询
    onSubmit() {
      this.getList();
    },
    //重置
    resize() {
      this.formInline = {};
      this.getList();
    },
    //再次考核
    examineAgain(row) {
      this.addForm.userId = row.userId;
      this.addForm.duration = row.duration;
      this.addForm.completedProcessStatusCount =
        row.completedProcessStatusCount;
      this.addForm.runningProcessStatusCount = row.runningProcessStatusCount;
      this.title = "再次考核";
      this.addVisible = true;
    },
  },
  //初始化数据
  created() {
    //列表数据
    this.getList();
    //用户数据
    this.listUser();
  },
};
</script>

<style lang="scss" scoped></style>